package com.tianji.learning.controller;

import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.pojo.QuestionAdminPageQuery;
import com.tianji.learning.pojo.QuestionFormDTO;
import com.tianji.learning.pojo.QuestionPageQuery;
import com.tianji.learning.pojo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import com.tianji.learning.vo.QuestionAdminVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 互动提问的问题表 控制器
 * </p>
 *
 * @author xjs
 */
@Api(tags = "InteractionQuestion管理")
@Slf4j
@RestController
@RequiredArgsConstructor
public class InteractionQuestionController {

    private final IInteractionQuestionService interactionQuestionService;

    @ApiOperation("新增提问")
    @PostMapping("/questions")
    public void addQuestions(@RequestBody QuestionFormDTO dto){
        interactionQuestionService.addQuestions(dto);
    }

    @ApiOperation("用户端的分页查询")
    @GetMapping("/questions/page")
    public PageDTO<QuestionVO> page(QuestionPageQuery query){
        return interactionQuestionService.pageQuery(query);
    }

    @ApiOperation("根据id查询问题详情")
    @GetMapping("/questions/{id}")
    public QuestionVO queryQuestionById(@PathVariable("id") Long id){
        return interactionQuestionService.queryQuestionById(id);
    }

    @ApiOperation("管理端分页查询")
    @GetMapping("/admin/questions/page")
    public PageDTO<QuestionAdminVO> adminPageQuery(QuestionAdminPageQuery query){
        long start = System.currentTimeMillis();
        PageDTO<QuestionAdminVO> pageDTO = interactionQuestionService.adminPageQuery(query);
        long end = System.currentTimeMillis();
        log.info("adminPageQuery use:{} ms", (end-start));
        return pageDTO;
    }


}
